#include "../head/HistoryForm_1.h"
#include "ui_historyform_1.h"
#include "../head/mainwindow.h"

HistoryForm_1::HistoryForm_1(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HistoryForm_1)
{
    ui->setupUi(this);
    this->setWindowTitle("采样数据");
    for (int i=0; i<DataPrimary_BUF_SIZE; i++)
    {
        x_1.append(i);
        y_1.append(mutiSignalDecode->DataPrimary_Temp[HIGH][i]);
    }
    curGraph_1 = ui->customPlot_1->addGraph();
    curGraph_1->setLineStyle(QCPGraph::lsLine);
    ui->customPlot_1->graph(0)->setPen(QPen(Qt::blue)); // 曲线的颜色
    ui->customPlot_1->plotLayout()->insertRow(0);
    m_title_1 = new QCPTextElement(ui->customPlot_1, "AD采样数据");
    ui->customPlot_1->plotLayout()->addElement(0, 0, m_title_1);
    curGraph_1->setData(x_1, y_1);
    // 为坐标轴添加标签
    //ui->customPlot->xAxis->setLabel("In-Phase");
    //ui->customPlot->yAxis->setLabel("Quadrature");
    // 设置坐标轴的范围，以看到所有数据
    ui->customPlot_1->graph(0)->rescaleAxes();
    ui->customPlot_1->legend->setVisible(false); // 显示图例
    ui->customPlot_1->replot();

    for (int i=0; i<DataPrimary_Fre_TempSize; i++)
    {
        x_2.append(i * 0.5);
        y_2.append(mutiSignalDecode->DataPrimary_Fre_Temp[HIGH][i]);
    }
    curGraph_2 = ui->customPlot_2->addGraph();
    curGraph_2->setLineStyle(QCPGraph::lsLine);
    ui->customPlot_2->graph(0)->setPen(QPen(Qt::blue)); // 曲线的颜色
    ui->customPlot_2->plotLayout()->insertRow(0);
    m_title_2 = new QCPTextElement(ui->customPlot_2, "采样数据频谱");
    ui->customPlot_2->plotLayout()->addElement(0, 0, m_title_2);
    curGraph_2->setData(x_2, y_2);
    // 为坐标轴添加标签
    //ui->customPlot->xAxis->setLabel("In-Phase");
    //ui->customPlot->yAxis->setLabel("Quadrature");
    // 设置坐标轴的范围，以看到所有数据
    ui->customPlot_2->graph(0)->rescaleAxes();
    ui->customPlot_2->legend->setVisible(false); // 显示图例
    ui->customPlot_2->replot();


    for (int i=0; i<DataPrimary_BUF_SIZE; i++)
    {
        x_3.append(i);
        y_3.append(mutiSignalDecode->Data_SignalDenoise[HIGH][i]);
    }
    curGraph_3 = ui->customPlot_3->addGraph();
    curGraph_3->setLineStyle(QCPGraph::lsLine);
    ui->customPlot_3->graph(0)->setPen(QPen(Qt::blue)); // 曲线的颜色
    ui->customPlot_3->plotLayout()->insertRow(0);
    m_title_3 = new QCPTextElement(ui->customPlot_3, "预滤波");
    ui->customPlot_3->plotLayout()->addElement(0, 0, m_title_3);
    curGraph_3->setData(x_3, y_3);
    // 为坐标轴添加标签
    //ui->customPlot->xAxis->setLabel("In-Phase");
    //ui->customPlot->yAxis->setLabel("Quadrature");
    // 设置坐标轴的范围，以看到所有数据
    ui->customPlot_3->graph(0)->rescaleAxes();
    ui->customPlot_3->legend->setVisible(false); // 显示图例
    ui->customPlot_3->replot();

    ui->customPlot_1->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
                                    QCP::iSelectLegend | QCP::iSelectPlottables);








    for (int i=0; i<DataPrimary_BUF_SIZE; i++)
    {
        x_4.append(i);
        y_4.append(mutiSignalDecode->DataPrimary_Temp[LOW][i]);
    }
    curGraph_4 = ui->customPlot_4->addGraph();
    curGraph_4->setLineStyle(QCPGraph::lsLine);
    ui->customPlot_4->graph(0)->setPen(QPen(Qt::blue)); // 曲线的颜色
    ui->customPlot_4->plotLayout()->insertRow(0);
    m_title_4 = new QCPTextElement(ui->customPlot_4, "AD采样数据");
    ui->customPlot_4->plotLayout()->addElement(0, 0, m_title_4);
    curGraph_4->setData(x_4, y_4);
    // 为坐标轴添加标签
    //ui->customPlot->xAxis->setLabel("In-Phase");
    //ui->customPlot->yAxis->setLabel("Quadrature");
    // 设置坐标轴的范围，以看到所有数据
    ui->customPlot_4->graph(0)->rescaleAxes();
    ui->customPlot_4->legend->setVisible(false); // 显示图例
    ui->customPlot_4->replot();

    for (int i=0; i<DataPrimary_Fre_TempSize; i++)
    {
        x_5.append(i * 0.5);
        y_5.append(mutiSignalDecode->DataPrimary_Fre_Temp[LOW][i]);
    }
    curGraph_5 = ui->customPlot_5->addGraph();
    curGraph_5->setLineStyle(QCPGraph::lsLine);
    ui->customPlot_5->graph(0)->setPen(QPen(Qt::blue)); // 曲线的颜色
    ui->customPlot_5->plotLayout()->insertRow(0);
    m_title_5 = new QCPTextElement(ui->customPlot_5, "采样数据频谱");
    ui->customPlot_5->plotLayout()->addElement(0, 0, m_title_5);
    curGraph_5->setData(x_5, y_5);
    // 为坐标轴添加标签
    //ui->customPlot->xAxis->setLabel("In-Phase");
    //ui->customPlot->yAxis->setLabel("Quadrature");
    // 设置坐标轴的范围，以看到所有数据
    ui->customPlot_5->graph(0)->rescaleAxes();
    ui->customPlot_5->legend->setVisible(false); // 显示图例
    ui->customPlot_5->replot();


    for (int i=0; i<DataPrimary_BUF_SIZE; i++)
    {
        x_6.append(i);
        y_6.append(mutiSignalDecode->Data_SignalDenoise[LOW][i]);
    }
    curGraph_6 = ui->customPlot_6->addGraph();
    curGraph_6->setLineStyle(QCPGraph::lsLine);
    ui->customPlot_6->graph(0)->setPen(QPen(Qt::blue)); // 曲线的颜色
    ui->customPlot_6->plotLayout()->insertRow(0);
    m_title_6 = new QCPTextElement(ui->customPlot_6, "预滤波");
    ui->customPlot_6->plotLayout()->addElement(0, 0, m_title_6);
    curGraph_6->setData(x_6, y_6);
    // 为坐标轴添加标签
    //ui->customPlot->xAxis->setLabel("In-Phase");
    //ui->customPlot->yAxis->setLabel("Quadrature");
    // 设置坐标轴的范围，以看到所有数据
    ui->customPlot_6->graph(0)->rescaleAxes();
    ui->customPlot_6->legend->setVisible(false); // 显示图例
    ui->customPlot_6->replot();


    ui->customPlot_4->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
                                    QCP::iSelectLegend | QCP::iSelectPlottables);

    for (int i=0; i<mutiSignalDecode->DemodulatorS_PriCh[0]->ModuleStructFSRC->Farrow_SigLen/2; i++)
    {
        x_7.append(i*2);
        y_7.append(0);
    }
    curGraph_7 = ui->customPlot_7->addGraph();
    curGraph_7->setLineStyle(QCPGraph::lsLine);
    ui->customPlot_7->graph(0)->setPen(QPen(Qt::blue)); // 曲线的颜色
    ui->customPlot_7->plotLayout()->insertRow(0);
    m_title_7 = new QCPTextElement(ui->customPlot_7, "插值滤波");
    ui->customPlot_7->plotLayout()->addElement(0, 0, m_title_7);
    curGraph_7->setData(x_7, y_7);
    // 为坐标轴添加标签
    //ui->customPlot->xAxis->setLabel("In-Phase");
    //ui->customPlot->yAxis->setLabel("Quadrature");
    // 设置坐标轴的范围，以看到所有数据
    ui->customPlot_7->graph(0)->rescaleAxes();
    ui->customPlot_7->legend->setVisible(false); // 显示图例
    ui->customPlot_7->replot();


    for (int i=0; i<mutiSignalDecode->DemodulatorS_PriCh[0]->ModuleStructFSRC->Farrow_SigLen/2; i++)
    {
        x_8.append(i*2);
        y_8.append(0);
    }
    curGraph_8 = ui->customPlot_8->addGraph();
    curGraph_8->setLineStyle(QCPGraph::lsLine);
    ui->customPlot_8->graph(0)->setPen(QPen(Qt::blue)); // 曲线的颜色
    ui->customPlot_8->plotLayout()->insertRow(0);
    m_title_8 = new QCPTextElement(ui->customPlot_8, "插值滤波");
    ui->customPlot_8->plotLayout()->addElement(0, 0, m_title_8);
    curGraph_8->setData(x_8, y_8);
    // 为坐标轴添加标签
    //ui->customPlot->xAxis->setLabel("In-Phase");
    //ui->customPlot->yAxis->setLabel("Quadrature");
    // 设置坐标轴的范围，以看到所有数据
    ui->customPlot_8->graph(0)->rescaleAxes();
    ui->customPlot_8->legend->setVisible(false); // 显示图例
    ui->customPlot_8->replot();

}

HistoryForm_1::~HistoryForm_1()
{
    delete ui;
}








//关闭窗口回到导航界面
 void HistoryForm_1::closeEvent(QCloseEvent *e)
 {
     //nf->show();
 }

 void HistoryForm_1::fft_demodule(){

 }

 void HistoryForm_1::drawHighWaveformPlot()
 {
     int type = 1;
     for (int i=0; i<DataPrimary_BUF_SIZE; i++)
     {
         x_1.replace(i,i);
         y_1.replace(i,mutiSignalDecode->DataPrimary_Temp[type][i]);

         x_3.replace(i,i);
         y_3.replace(i,mutiSignalDecode->Data_SignalDenoise[type][i]);

     }
     curGraph_1->setData(x_1, y_1);
     ui->customPlot_1->graph(0)->rescaleAxes();
     // 重画图像
     ui->customPlot_1->replot();


     curGraph_3->setData(x_3, y_3);
     ui->customPlot_3->graph(0)->rescaleAxes();
     // 重画图像
     ui->customPlot_3->replot();

     for (int i=0; i<DataPrimary_Fre_TempSize; i++)
     {
         x_2.replace(i,i * 0.5);
         y_2.replace(i,mutiSignalDecode->DataPrimary_Fre_Temp[type][i]);
     }
     curGraph_2->setData(x_2, y_2);
     ui->customPlot_2->graph(0)->rescaleAxes();
     // 重画图像
     ui->customPlot_2->replot();


//     for (int i=0; i<temp_farrow_len; i++)
//     {
//         //x_7.replace(i,i);
//         y_7.replace(i,mutiSignalDecode->Farrow_Temp[type][i]);
//     }
     curGraph_7->setData(x_7, y_7);
     ui->customPlot_7->graph(0)->rescaleAxes();
     // 重画图像
     ui->customPlot_7->replot();
 }

 void HistoryForm_1::drawLowWaveformPlot()
 {
     int type = 0;
     for (int i=0; i<DataPrimary_BUF_SIZE; i++)
     {
         x_4.replace(i,i);
         y_4.replace(i,mutiSignalDecode->DataPrimary_Temp[type][i]);

         x_6.replace(i,i);
         y_6.replace(i,mutiSignalDecode->Data_SignalDenoise[type][i]);

     }
     curGraph_4->setData(x_4, y_4);
     ui->customPlot_4->graph(0)->rescaleAxes();
     // 重画图像
     ui->customPlot_4->replot();


     curGraph_6->setData(x_6, y_6);
     ui->customPlot_6->graph(0)->rescaleAxes();
     // 重画图像
     ui->customPlot_6->replot();

     for (int i=0; i<DataPrimary_Fre_TempSize; i++)
     {
         x_5.replace(i,i * 0.5);
         y_5.replace(i,mutiSignalDecode->DataPrimary_Fre_Temp[type][i]);
     }
     curGraph_5->setData(x_5, y_5);
     ui->customPlot_5->graph(0)->rescaleAxes();
     // 重画图像
     ui->customPlot_5->replot();


     for (int i=0; i<mutiSignalDecode->DemodulatorS_PriCh[0]->ModuleStructFSRC->Farrow_SigLen/2; i++)
     {
          x_8.replace(i,i*2);
         y_8.replace(i,mutiSignalDecode->Farrow_Temp[type][i*2]);
     }
     curGraph_8->setData(x_8, y_8);
     ui->customPlot_8->graph(0)->rescaleAxes();
     // 重画图像
     ui->customPlot_8->replot();
 }

